@extends('back.adminbase')
@section('content')
	<section class="hbox stretch">
		@include("back.public.left")

		<aside>
			<section class="vbox">

				<header class="header bg-white b-b clearfix">
					<form class="talbe-search" method="get" action="">
						<div class="row m-t-sm">
							<div class="col-sm-12 m-b-xs">
								<div class="btn-group" role="group">
									<strong style="line-height:30px;">添加漂流柜</strong>
								</div>
								<div class="btn-group pull-right">
									<a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
										<i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
									</a>
								</div>
							</div>
						</div>
					</form>
				</header>
				<section class="scrollable  wrapper w-f">
					<section class="panel panel-default ">
						<div class="row m-l-none m-r-none bg-light lter">
							<div class="container" style="padding: 20px 0px">
								<form id="formclass" class="form-horizontal" style="padding-top: 15px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">柜名<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="name"
                                                   placeholder="请输入名称">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">类型<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <select name='type' class="input-sm">
                                                @foreach([1=>'漂流柜',2=>'还书箱'] as $k=>$v)
                                                    <option value="{{ $k}}">{{ $v }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">地区 </label>
                                        <div class="col-sm-6 ">
                                            <select id="region_id" class="input-sm">
                                                @foreach($parent as $v)
                                                    <option value="{{ $v->id }}">{{ $v->name }}</option>
                                                @endforeach
                                            </select>
                                            <select id="region_id2" class="input-sm" name="chid">
                                            </select>
                                            <select id="region_id3" class="input-sm" name="cid">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">地址<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="address"
                                                   placeholder="请输入地址">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">经度<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="longi"
                                                   placeholder="请输入经纬度">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">纬度<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="lati"
                                                   placeholder="请输入经纬度">
                                        </div>
                                    </div>
									<div class="form-group">
										<label class="col-sm-3 control-label"></label>
										<div class="col-sm-2 ">
											<button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
										    <input type="checkbox" id="back">
                                            <label for="back">返回列表</label>
										</div>
									</div>
								</form>
							</div>
						</div>

					</section>
				</section>


			</section>
		</aside>
	</section>
@endsection
@section('addscript')
    <script src="{{ url('/') }}/laydate/laydate.js"></script>
	<script>
        var load;
		$(function(){
            var first = $('#region_id').val();
            $.post("{{ url('back/book/pull1') }}",{pid:first},function(data){
                if(data){
                    var region_id2 = $("#region_id2");
                    $("option",region_id2).remove();
                    $.each(data,function(index,array){
                        var option = "<option value='"+array['id']+"'>"+array['name']+"</option>";
                        region_id2.append(option);
                    });
                    var first2 = $('#region_id2').val();
                    $.post("{{ url('back/book/pull') }}",{pid:first2},function(data){
                        if(data){
                            var region_id3 = $("#region_id3");
                            $("option",region_id3).remove();
                            $.each(data,function(index,array){
                                var option = "<option value='"+array['id']+"'>"+array['name']+"</option>";
                                region_id3.append(option);
                            });
                        }
                    });
                }
            });
            //二级联动
            $("#region_id").change(function() {
                var first = $(this).val();
                $.post("{{ url('back/book/pull') }}",{pid:first},function(data){
                    if(data){
                        var region_id2 = $("#region_id2");
                        $("option",region_id2).remove();
                        $.each(data,function(index,array){
                            var option = "<option value='"+array['id']+"'>"+array['name']+"</option>";
                            region_id2.append(option);
                        });
                        var first2 = $('#region_id2').val();
                        $.post("{{ url('back/book/pull') }}",{pid:first2},function(data){
                            if(data){
                                var region_id3 = $("#region_id3");
                                $("option",region_id3).remove();
                                $.each(data,function(index,array){
                                    var option = "<option value='"+array['id']+"'>"+array['name']+"</option>";
                                    region_id3.append(option);
                                });
                            }
                        });
                    }
                });
            });
            //二级联动
            $("#region_id2").change(function() {
                var first = $(this).val();
                $.post("{{ url('back/book/pull3') }}",{pid:first},function(data){
                    if(data){
                        var region_id3 = $("#region_id3");
                        $("option",region_id3).remove();
                        $.each(data,function(index,array){
                            var option = "<option value='"+array['id']+"'>"+array['name']+"</option>";
                            region_id3.append(option);
                        });
                    }
                });
            });
            var a = 0;
			$("#formclass").submit(function(e){
                if (a==1) {
                    return false;
                }
                a++;
                var data = $(this).serialize();
                e.preventDefault();
                $.ajax({
                    url:"{{ url('back/shelf/save/0') }}",
                    type:"post",
                    dataType:"json",
                    data:data,
                    success:function(data){
                        layer.close(load);
                        layer.msg(data.msg);
                        location.href = '{{ url('back/shelf') }}';
                    },
                    error:function(data){
                        layer.close(load);
                        layer.msg(data.responseJSON.msg,{icon:5});
                    }
                })
			})


		});
	</script>
@endsection
